<?php
#This page is used to expand children pages for the admin pages



#LOADING PAGES
include "../../site_specific/project.php";
include "../../includes/constants.php";
include "../../site_specific/external_constants.php";
include "../../includes/phpmailer/class.phpmailer.php";
include "../../includes/phpmailer/class.smtp.php";
include "../../includes/utilities.php";
include "../../includes/pages.php";
include "../../includes/database.php";
include "../../includes/users.php";
include "../../includes/date.php";
include "../../includes/text.php";
include "../../includes/files.php";
include "../../includes/tableproperties.php";
include "../../includes/shopping_cart.php";

# Establish database connection
establishDatabaseConnection();

# Create Pages object and provide with basic details of all pages
$page_parent = $_GET["id"];

$page_section = $_GET["section"];

$output = "";

$output .= "<table cellspacing=\"0\" align=\"left\">";

if($page_section != 'junkbox'){
	
	$PAGES = getSectionPages($page_section);

	if(@$_GET["id"]){
		
		#Get page ids
		foreach($PAGES -> getPageIDs() as $PAGES_IDS){
			
			#Get page pointer
			$page_pointer =  $PAGES -> getPage($PAGES_IDS);
			
			#Only for the children of current selected page parent
			if($page_pointer -> getData('p_parent')==$page_parent){
				
				$Lower_Page = $PAGES -> getPagesWithValues(array("p_parent"), array($PAGES_IDS));
				#If those page` children is not empty
				if(count($Lower_Page) > 0){
			
					$output.="<tr><td valign=\"top\" style=\"border-color: white;border-style: solid;\"><img id=\""."img_".$PAGES_IDS."\" src=\"../assets/images/tree/folder_closed.png\" onclick=\"ExpandParentPage('".$page_section."','".$PAGES_IDS."');\"/></td><td style=\"border-color: white;border-style: solid;\" align=\"left\">";
				
					$output.="<a target=\"_blank\" id=\"a_".$PAGES_IDS."\" href=\"../" . $page_section . "/" . $PAGES_IDS . ".php\" onmouseover=\"ShowControlPanel('".getPageStatusName($page_pointer -> getData("p_status"))."','".$PAGES_IDS."')\" onclick=\"\" style=\"text-decoration:none;\">".$page_pointer -> getData("p_name")."(".$PAGES_IDS.")"."</a><br/><div align=\"left\" id=\""."div_".$PAGES_IDS."\"></div></td></tr>";
				}
				else{
					$output.="<tr><td valign=\"top\" style=\"border-color: white;border-style: solid;\"><img id=\""."img_".$PAGES_IDS."\" src=\"../assets/images/tree/document.png\"/></td><td style=\"border-color: white;border-style: solid;\" align=\"left\">";
				
					$output.="<a target=\"_blank\" id=\"a_".$PAGES_IDS."\" href=\"../" . $page_section . "/" . $PAGES_IDS . ".php\" onmouseover=\"ShowControlPanel('".getPageStatusName($page_pointer -> getData("p_status"))."','".$PAGES_IDS."')\" onclick=\"\" style=\"text-decoration:none;\">".$page_pointer -> getData("p_name")."(".$PAGES_IDS.")"."</a><br/></td></tr>";
				}
			}
		}
	}
	else{ 
		
		#Get page ids
		foreach($PAGES -> getPageIDs() as $PAGES_IDS){
			
			#Get page pointer
			$page_pointer =  $PAGES -> getPage($PAGES_IDS);
			
			#Only for the children of current selected page parent
			if($page_pointer -> getData('p_parent')==''){
				
				$Lower_Page = $PAGES -> getPagesWithValues(array("p_parent"), array($PAGES_IDS));
				
				#If those page` children is not empty
				if(count($Lower_Page)!=0){
					
					$output.="<tr><td valign=\"top\" style=\"border-color: white;border-style: solid;\"><img id=\""."img_".$PAGES_IDS."\" src=\"../assets/images/tree/folder_closed.png\" onclick=\"ExpandParentPage('".$page_section."','".$PAGES_IDS."');\"/></td><td style=\"border-color: white;border-style: solid;\" align=\"left\">";
				
					$output.="<a target=\"_blank\" id=\"a_".$PAGES_IDS."\" href=\"../" . $page_section . "/" . $PAGES_IDS . ".php\" onmouseover=\"ShowControlPanel('".getPageStatusName($page_pointer -> getData("p_status"))."','".$PAGES_IDS."')\" onclick=\"\" style=\"text-decoration:none;\">".$page_pointer -> getData("p_name")."(".$PAGES_IDS.")"."</a><br/><div align=\"left\" id=\""."div_".$PAGES_IDS."\"></div></td></tr>";
				}
				else{
						
					$output.="<tr><td valign=\"top\" style=\"border-color: white;border-style: solid;\"><img id=\""."img_".$PAGES_IDS."\" src=\"../assets/images/tree/document.png\"/></td><td style=\"border-color: white;border-style: solid;\" align=\"left\">";
				
					$output.="<a target=\"_blank\" id=\"a_".$PAGES_IDS."\" href=\"../" . $page_section . "/" . $PAGES_IDS . ".php\" onmouseover=\"ShowControlPanel('".getPageStatusName($page_pointer -> getData("p_status"))."','".$PAGES_IDS."')\" onclick=\"\" style=\"text-decoration:none;\">".$page_pointer -> getData("p_name")."(".$PAGES_IDS.")"."</a><br/></td></tr>";
				}
			}	
			
		}

	}
}
else{
	
	$sql = "SELECT * FROM ".$PROJECT_DB_TABLES["pages"]." WHERE p_status>=3 order by p_id";
	
	$result = getRecord($sql);
		
	foreach($result as $key => $value){
			
		$output.="<tr><td valign=\"top\" style=\"border-color: white;border-style: solid;\"><img id=\""."img_".$value["p_id"]."_junk\" src=\"../assets/images/tree/document.png\"/></td><td style=\"border-color: white;border-style: solid;\" align=\"left\">";
				
		$output.="<a target=\"_blank\" id=\"a_".$value["p_id"]."_junk\" onmouseover=\"ShowJunkboxControlPanel('".getPageStatusName($value["p_status"])."','".$value["p_id"]."')\" onclick=\"\" style=\"text-decoration:none;\">".$value["p_name"]."(".$value["p_id"].")"."</a><br/><div align=\"left\" id=\""."div_".$value["p_id"]."_junk\"></div></td></tr>";
	}
}
//header('Access-Control-Allow-Origin: *');
//echo $output;
$output .= "</table>";

echo $output;

?>